<?php
	include_once 'isLogin.php';
	$add_success = null;
	$table_name = "company_levequestion";
	$table= "company_levequestion";
	
	//删除
	if($_GET['action']=='del'){
		echo $commonc->del($table_name,$_POST['id']);
		exit();
	}
	
	
	if ($_GET['upid']!=''&&$_GET['level']!=null) {
	     $level = $_GET['level'];
	     $upid = $_GET['upid'];
		 $categories=$_GET['categories'];
	}
//列出具体问题
if($_GET['id']!=null && $_GET['id']!=''){
	$sql=$table_name." where title_id=".$_GET['id']." and title_level=2 order by list_id";
	$res=$commonc->getList($sql, $sqlnum='', $key="list_id,conent,id",$debug='0');
	//var_dump($res['result']);
}
//查出一级标题
if($_GET['id']!=null && $_GET['id']!=''){
	$sql=$table_name." where id=".$_GET['id']." and title_level=1";
	$result=$commonc->getList($sql, $sqlnum='', $key="list_id,conent",$debug='0');
	//var_dump($result['result']);
}	

/*
*  评级问题的设置与重置
*/
if($_POST['submit']){
	$sql=$table." where list_id=".$_POST['list']." and title_level=2 and title_id=".$_GET['id'];
	$title=$commonc->getList($sql, $sqlnum='', $key="*",$debug='0');
	if(isset($title['result'])){
		$data=array('conent'=>$_POST['conent']);
	    $result=$commonc->update($table_name,$data,"title_id=".$_GET['id']." and list_id=".$_POST['list']);
		$add_success = 2;
	}else{
		$datas=array('list_id'=>$_POST['list'],'conent'=>$_POST['conent'],'title_id'=>$_GET['id'],'title_level'=>'2');
		$commonc->insert($table_name,$datas);
		$add_success = 1;
	}
	echo $commonc->submitAlert('成功',$href);
}

	if($_GET['action']=='add'){
		
		//插入数据
		if(is_array($_POST['values'])){
			foreach($_POST['values'] as $k=>$v){
				$arr[$key_index[$k]] = $v;
			}
		}
		$commonc->insert($table_name,$arr);
		$id = $commonc->insert_id();
	}

	
	//修改
	if($_GET['action']=='edit'){
		$arr = array($key_index[$_POST['index']]=>$_POST['value']);
		echo $commonc->update($table_name,$arr,"id='".$_POST['value_id']."'");
		exit();
	}
	
	//修改状态
	if($_GET['action']=='state'){
		echo $commonc->changeState($table_name,$_POST['id'],$_POST['key'],$colors[$_POST['key']],$names[$_POST['key']]);
		exit();
	}
	
	//排序
	if($_GET['action']=='sort'){
		if($_POST['type']=='down') $type = "prev";
		if($_POST['type']=='up') $type = "next";
		$sort = $commonc->sortChange($table_name, $_POST['id'], $type);
		echo $sort['id'];
		exit();
	}
/*
*获取本类别下放的问题列表
*
*/
	$sql=$table_name." where categories_id=".$_GET['id']." order by list_id";
	$row=$commonc->getList($sql, $sqlnum='', $key="*",$debug='0');
    $smarty->assign('smart',$row['result']);
	//获得数据
	if($_GET['id']!=false){
		$row=$commonc->getInfo($table_name,$_GET['id']);
		$smarty->assign('row',$row);
		$smarty->assign('area',$area);
	}
	$smarty->assign('add_success',$add_success);
	$smarty->assign('res',$res['result']);
	$smarty->assign('result',$result['result']);
	$smarty->display($_filename.".html");
	
?>